home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-25 | 5.3 KB | 185 lines | [TEXT/PJMM] |
- program TestGrafSys;
-
- { 3d GrafSys Demo Program}
- { Vers. 1.1 }
- { (c) 1992 by Christian Franz }
-
- { Program to demonstrate rotation around arbitrary achsis. The achsis always runs through }
- { the fighter's bow and the origin (point 30). these two transformed points are used for the }
- { definition of the arbitrary achsis. }
-
-
-
- uses
- (* Matrix, Transformations, Data3D, ResourceAccess, Grafsys, Screen3D; *)
- GrafSys, Screen3D;
-
- const
- theWindowID = 400;
- degree = 0.01745329; (* π/180 *)
-
- var
- theWindow: WindowPtr;
- theInt: INTEGER;
- thePort: Graf3DPtr;
- theMaster: Graf3DPtr;
- Pyramid, Cube, xFighter: GrafObjPtr;
- theEvent: EventRecord;
- dx, dy, dz: integer;
- r: Rect;
- p1, p2: Vector4;
-
-
- (* Generate an object that looks like the famous x-Fighter in the world famous motion *)
- (* picture 'Star Wars' *)
- (**)
- (* Notice especially the definition of points 9 (bow) and 30 *)
-
- procedure makeFighter (var Obj: GrafObjPtr);
- var
- OK: boolean;
- count: integer;
-
- begin
- Obj := NewObject;
- OK := AddPoint(Obj, -160, 0, 0, count);
-
- OK := AddPoint(Obj, -80, -10, 10, count);
- OK := AddPoint(Obj, 110, -10, 10, count);
- OK := AddPoint(Obj, 110, 10, 10, count);
- OK := AddPoint(Obj, -80, 10, 10, count);
-
- OK := AddPoint(Obj, -80, -10, -10, count);
- OK := AddPoint(Obj, 110, -10, -10, count);
- OK := AddPoint(Obj, 110, 10, -10, count);
- OK := AddPoint(Obj, -80, 10, -10, count);
-
- OK := AddLine(Obj, 1, 2);
- OK := AddLine(Obj, 2, 3);
- OK := AddLine(Obj, 3, 4);
- OK := AddLine(Obj, 4, 5);
- OK := AddLine(Obj, 6, 7);
- OK := AddLine(Obj, 7, 8);
- OK := AddLine(Obj, 8, 9);
-
- OK := AddLine(Obj, 9, 1);
- OK := AddLine(Obj, 1, 5);
- OK := AddLine(Obj, 1, 6); (* bow *)
-
- OK := AddPoint(Obj, 60, 10, 10, count); (* 10 *)
- OK := AddPoint(Obj, 60, 80, 40, count);(* 11*)
- OK := AddPoint(Obj, 100, 80, 40, count);(* 12 *)
- OK := AddPoint(Obj, 100, 10, 10, count);(* 13 *)
- OK := AddLine(Obj, 10, 11);
- OK := AddLine(Obj, 11, 12);
- OK := AddLine(Obj, 12, 13);
-
- OK := AddPoint(Obj, 50, 10, -10, count); (* 14 *)
- OK := AddPoint(Obj, 50, 80, -40, count);(* 15*)
- OK := AddPoint(Obj, 100, 80, -40, count);(* 16 *)
- OK := AddPoint(Obj, 100, 10, -10, count);(* 17 *)
- OK := AddLine(Obj, 14, 15);
- OK := AddLine(Obj, 15, 16);
- OK := AddLine(Obj, 16, 17);
-
- OK := AddPoint(Obj, 50, -10, 10, count); (* 18 *)
- OK := AddPoint(Obj, 50, -80, 40, count);(* 19*)
- OK := AddPoint(Obj, 100, -80, 40, count);(* 20 *)
- OK := AddPoint(Obj, 100, -10, 10, count);(* 21 *)
- OK := AddLine(Obj, 18, 19);
- OK := AddLine(Obj, 19, 20);
- OK := AddLine(Obj, 20, 21);
-
- OK := AddPoint(Obj, 50, -10, -10, count); (* 22 *)
- OK := AddPoint(Obj, 50, -80, -40, count);(* 23*)
- OK := AddPoint(Obj, 100, -80, -40, count);(* 24 *)
- OK := AddPoint(Obj, 100, -10, -10, count);(* 25 *)
- OK := AddLine(Obj, 22, 23);
- OK := AddLine(Obj, 23, 24);
- OK := AddLine(Obj, 24, 25);
-
- OK := AddPoint(Obj, 20, 80, 40, count); (* 26 *)
- OK := AddPoint(Obj, 20, 80, -40, count);(* 27 *)
- OK := AddPoint(Obj, 20, -80, 40, count);(* 28 *)
- OK := AddPoint(Obj, 20, -80, -40, count);(* 29 *)
- OK := AddLine(Obj, 26, 11);
- OK := AddLine(Obj, 27, 15);
- OK := AddLine(Obj, 28, 19);
- OK := AddLine(Obj, 29, 23); (* weapons done *)
-
- OK := AddLine(Obj, 4, 8);
- OK := AddLine(Obj, 3, 7);
-
- OK := AddPoint(Obj, 0, 0, 0, count); (* we need this point for free-rotate *)
- (* punkt 30 *)
- end;
-
- procedure getmouserot (var dx, dy, dz: integer);
-
- var
- thePoint: point;
-
- begin
- GetMouse(thePoint);
- dx := 0;
- dy := 0;
- dz := 0;
- if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
- begin
- dx := 5;
- end;
- if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
- begin
- dy := 5;
- end;
- if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
- begin
- dz := 5;
- end;
- if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
- begin
- end;
- if button then
- begin
- dx := -dx;
- dy := -dy;
- dz := -dz;
- end;
- end;
-
-
- begin
- theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
- SetPort(theWindow); (* draw in this window *)
-
- MoveTo(10, 10);
- DrawString('3D Grafiksystem. Object: X-Fighter. (C) 1991 by C. Franz');
- InitGrafSys;
- NewGrafport(theWindow^.portRect, thePort);
- MoveTo(10, thePort^.bottom - 0);
- DrawString(' Press Button to Exit');
- MakeFighter(xFighter);
-
- SetEye(TRUE, 0, 0, -100, 0, 0, 0, 1.512, FALSE);
- ObjTranslate(xFighter, 0, 0, 100);
- ObjRotate(xFighter, 0 * degree, 0 * degree, 0);
- ObjScale(xFighter, 1, 1, 1);
- SetAutoErase(xFighter, TRUE);
- fDrawObject(xFighter);
- repeat
- GetMouseRot(dx, dy, dz);
- SystemTask;
- if (dx + dy + dz <> 0) then
- begin
- fDrawObject(xfighter); (* draw Object *)
- ObjRotate(xFighter, dx * degree, dy * degree, dz * degree)
- end
- else (* instead of idle, we will freerotate it now! oh, yeah! *)
- begin
- fDrawObject(xFighter);
- p1 := ObjPoint(xFighter, 1);
- p2 := ObjPoint(xFighter, 30);
- ObjFreeRotateArb(xFighter, p1, p2, 5 * degree);
- end;
- until Button;
- end.